package com.game.dao.user.account;

import com.coment.po.UserAccount;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.lang.NonNull;

import java.util.List;


public interface UserAccountDao extends MongoRepository<UserAccount, String> {

    UserAccount findByUserInfoId(Integer userInfoId);

    default UserAccount findByUserInfoIdOrCreate(Integer userInfoId) {
        UserAccount byUserInfoId = findByUserInfoId(userInfoId);
        if (byUserInfoId == null) {
            byUserInfoId = new UserAccount();
            byUserInfoId.setUserInfoId(userInfoId);
            return insert(byUserInfoId);
        }
        return byUserInfoId;
    }

    @NonNull
    @Override
    <S extends UserAccount> List<S> saveAll(@NonNull Iterable<S> entities);

    @NonNull
    @Override
    <S extends UserAccount> S save(@NonNull S entity);

    List<UserAccount> findAllByUserInfoIdIn(List<Integer> userInfoIds);
}
